import { Controller } from "../../mvc/core/Controller";
import { IView } from "../../mvc/interfaces/IView";
import { ViewItemModule } from "../../../modules/ViewItemModule";
import { Dispatcher } from "../../mvc/core/Dispatcher";
import { EventName } from "../mvc/EventName";
import { DataEvent } from "../events/DataEvent";
import { ItemData } from "../resource/info/ItemData";
import { ItemsUtil } from "../view/shortcuts/item/ItemsUtil";
import { Language } from "../../../extend/language/Language";
//class ViewItemController
    
    export  class ViewItemController extends Controller
    {
       

        protected /* override */ initView(): IView
        {
            if (!this._viewItemModule) 
            {
                this._viewItemModule = new ViewItemModule();
            }
            return this._viewItemModule;
        }

        public get viewItemModule(): ViewItemModule
        {
            if (!this._viewItemModule) 
            {
                this._viewItemModule = new ViewItemModule();
            }
            return this._viewItemModule;
        }

        protected /* override */ initServer(): void
        {
            Dispatcher.addEventListener(EventName.GetNewEquip, this.getNewEquip);
            Dispatcher.addEventListener(EventName.GetNewMagicWeapon, this.onGetNewMagicWeapon);
            return;
        }

        /* internal  */getNewEquip(arg1: DataEvent): void
        {
            var loc1=arg1.data as ItemData;
            if (loc1) 
            {
                if (ItemsUtil.isMoveGoodEquip(loc1)) 
                {
                    this.showView(loc1);
                }
            }
            return;
        }

        /* internal  */onGetNewMagicWeapon(arg1: DataEvent): void
        {
            var loc1=arg1.data.item as ItemData;
            this.showView(loc1, true, Language.getString(27693));
            return;
        }

        public showView(arg1: ItemData, ... rest): void
        {
            if (this.initView()) 
            {
                this._viewItemModule.update(arg1, rest);
                this._viewItemModule.show();
            }
            return;
        }

        private /* var */_viewItemModule: ViewItemModule;
    }
